/**
 * Created by Administrator on 2017/3/15.
 */
//轮播图
function carousel(caro_wrap,width,height,AniTime,stayTime) {
    var caro_wrap = $("."+caro_wrap);
    caro_wrap.css({width:width,height:height});
    caro_wrap.find("ul.pic_box li").css({width:width,height:height});
    var carousel = caro_wrap.find(".carousel");
    var pic_box = carousel.find("ul.pic_box");

    var pic_num = carousel.find("ul.pic_box li").length;
    var stepWidth = carousel.width(); //每次滚动要移动的距离
    carousel.find("ul.pic_box li").width(stepWidth);
    carousel.find("ul.pic_box li").height(height);
    var moveWidth = stepWidth; //初始偏移量
    var canClick = true;
    pic_box.append(carousel.find(".pic_box li").first().clone(true)); //复制第一张到最后面
    pic_box.prepend(carousel.find(".pic_box li").eq(-2).clone(true)); //复制倒数第二张（实际是原始的最后一张）到最前面
    pic_box.css("x", -stepWidth);
    var cur_show = 0;
    var next_show = 1;
    /**添加控制点*/
    for(var i = 0; i < pic_num; i++) {
        var panle_li = $("<li class='control'></li>");
        carousel.find(".panel").append(panle_li);
    }
    carousel.find(".control").eq(0).addClass("active"); //初始值第一个控制点默认active；

    /*****左右箭头添加监听事件******/
    carousel.find(".left").on("click", function() { //左点击实现
        if(canClick) {
            canClick = false;
            Tleft()
        }

    });
    carousel.find(".right").on("click", function() { //右点击实现
        if(canClick) {
            canClick = false;
            Tright()
        }
    });

    function Tleft() { //左按钮事件
        next_show = cur_show - 1;
        _scroll();
    }

    function Tright() { //右按钮事件
        next_show = cur_show + 1;
        _scroll();
        //控制点

    }
    /***给控制点添加点击事件****/
    carousel.find(".control").on("click", function() {
        next_show = $(this).index();
        _scroll();
    })
    /******定时器**********/
    var t = setInterval(function() {
        Tright();
    }, AniTime+stayTime)
    carousel.on("mouseover", function() {
        clearInterval(t)
    })
    carousel.on("mouseout", function() {
        t = setInterval(function() {
            Tright();
        }, AniTime+stayTime)
    })
    /*********提取出滚动函数*********/
    function _scroll() {
        //关键点,让moveWidth移动目标位置和当前位置的差距
        moveWidth += ((next_show - cur_show) * stepWidth);
        cur_show = next_show; //更新当前位置为目标位置
        pic_box.transit({
            "x": -moveWidth
        }, AniTime, function() {
            canClick = true;
            //console.log(cur_show,pic_num);
            if(cur_show > pic_num - 1) { //如果到了复制的第一张图片,就瞬间移动到原本的第一张图
                moveWidth = stepWidth;
                cur_show = 0;
                pic_box.css("x", -stepWidth)
            }
            if(cur_show < 0) {
                moveWidth = pic_num * stepWidth;
                cur_show = pic_num - 1;
                pic_box.css("x", -moveWidth)
            }
        })
        var tem = cur_show > pic_num - 1 ? 0 : cur_show;
        carousel.find(".control").eq(tem).addClass("active").siblings(".control").removeClass("active");
    }
}
carousel("demo1",$(".section_kv_section").width,$(".section_kv_section").height,500,2000);
//判断滚动条

setInterval(function () {
    if(window.pageYOffset>($(".section_seckill").offset().top)-50){
        $(".scroll_so").css("top","0");
    }else{
        $(".scroll_so").css("top","-50px");
    }
    if(window.pageYOffset>1500){
        $(".left_menu").fadeIn("slow");
        if(window.pageYOffset>($(".bl1").offset().top)&&window.pageYOffset<($(".bl2").offset().top)){

            $(".left_menu_list1").css("background","#c81623");
        }else {
            $(".left_menu_list1").css("background","#918888");
        }
         if (window.pageYOffset>($(".bl2").offset().top)&&window.pageYOffset<($(".bl3").offset().top)){

            $(".left_menu_list2").css("background","#c81623");
        }else {
             $(".left_menu_list2").css("background","#918888");
         }
        if (window.pageYOffset>($(".bl3").offset().top)&&window.pageYOffset<($(".bl4").offset().top)){
            $(".left_menu_list3").css("background","#c81623");
        }else  {
            $(".left_menu_list3").css("background","#918888");
        }
        if (window.pageYOffset>($(".bl4").offset().top)&&window.pageYOffset<($(".bl5").offset().top)){
            $(".left_menu_list4").css("background","#c81623");
        }else {
            $(".left_menu_list4").css("background","#918888");
        }
        if (window.pageYOffset>($(".bl5").offset().top)&&window.pageYOffset<($(".bl6").offset().top)){
            $(".left_menu_list5").css("background","#c81623");
        }else {
            $(".left_menu_list5").css("background","#918888");
        }
        if (window.pageYOffset>($(".bl6").offset().top)&&window.pageYOffset<($(".bl7").offset().top)){
            $(".left_menu_list6").css("background","#c81623");
        }else {
            $(".left_menu_list6").css("background","#918888");
        }
        if (window.pageYOffset>($(".bl7").offset().top)&&window.pageYOffset<($(".bl8").offset().top)){
            $(".left_menu_list7").css("background","#c81623");
        }else {
            $(".left_menu_list7").css("background","#918888");
        }
        if (window.pageYOffset>($(".bl8").offset().top)&&window.pageYOffset<($(".bl9").offset().top)){
            $(".left_menu_list8").css("background","#c81623");
        }else {
            $(".left_menu_list8").css("background","#918888");
        }
        if (window.pageYOffset>($(".bl9").offset().top)&&window.pageYOffset<($(".bl10").offset().top)){
            $(".left_menu_list9").css("background","#c81623");
        }else {
            $(".left_menu_list9").css("background","#918888");
        }
        if (window.pageYOffset>($(".bl10").offset().top)){
            $(".left_menu_list10").css("background","#c81623");
        }else {
            $(".left_menu_list10").css("background","#918888");
        }



    }else{
        $(".left_menu").fadeOut("slow");

    }
},100)
